import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, ExecuteButton } from '../Common/options'
import { InfoTypeManageTree } from '../Common/Conversion'

export const InfoTypeManage = async ({ url, OptionsEvent, actionRef }) => {
    const parentUuid = await InfoTypeManageTree()
    let data = {
        pageSize: 100,
        params: { pageIndex: 1 },
        hideInSearch: true,
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            <ExecuteButton
                actionRef={actionRef}
                OptionsEvent={OptionsEvent}
                url="posSyncInfoTypeManageToMenu"
                type="primary"
                title="同步文件柜菜单"
                tips="同步成功!"
            />,
            <AddDataButton OptionsEvent={OptionsEvent} url={url} type="primary" icon="add" title="新增" />,
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.code, rules: true },
            { ...commonTableList.tableName, title: '类型名称' },
            {
                ...commonTableList.parentUuid,
                fieldProps: {
                    fieldNames: { label: 'tableName', value: 'uuid' },
                    options: parentUuid,
                },
            },
            {
                dataIndex: 'fileType',
                title: '菜单类型',
                valueType: 'select',
                valueEnum: BuiltInData.InfoFileType,
                width: 200,
                hideInSearch: true,
            },
            { ...commonTableList.sortId, rules: true },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        // children.findIndex(v => v.uuid === '1c9fa68d-0b9b-47d5-be27-fdef5bacf8f9') !== -1 &&
                        <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" url={url} data={record} />,
                        // children.findIndex(v => v.uuid === 'c25870d3-e178-4bb4-8197-ebcf690587a5') !== -1 &&
                        <DelDataButton
                            OptionsEvent={OptionsEvent}
                            key="del"
                            title="删除"
                            url={url}
                            uuid={record.uuid}
                        />,
                    ]
                },
            },
        ],
    }
    return data
}
